package edu.udo.sopra10.chaturaji.entities.transfer;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * Two ordered dice rolls.
 * 
 * @author Simon Dierl
 */
public final class DiceRolls {
	/**
	 * The first roll.
	 */
	private final DiceRoll firstRoll;

	/**
	 * The second roll.
	 */
	private final DiceRoll secondRoll;

	/**
	 * Accumulate two dice rolls in a new {@link DiceRolls}.
	 * 
	 * @param firstRoll
	 *            the first roll, must be in {@code [1, 6]}.
	 * @param secondRoll
	 *            the second roll, must be in {@code [1, 6]}.
	 */
	public DiceRolls(final byte firstRoll, final byte secondRoll) {
		this.firstRoll = new DiceRoll(firstRoll);
		this.secondRoll = new DiceRoll(secondRoll);
	}

	@Override
	public boolean equals(final Object obj) {
		if (obj == this) {
			return true;
		} else if ((obj == null) || !(obj instanceof DiceRolls)) {
			return false;
		} else {
			final DiceRolls diceRolls = (DiceRolls) obj;
			return new EqualsBuilder().append(firstRoll, diceRolls.firstRoll)
					.append(secondRoll, diceRolls.secondRoll).isEquals();
		}
	}

	/**
	 * Get the first dice roll.
	 * 
	 * @return the first roll, never {@code null}.
	 */
	public DiceRoll getFirstRoll() {
		return firstRoll;
	}

	/**
	 * Get the second dice roll.
	 * 
	 * @return the second roll, never {@code null}.
	 */
	public DiceRoll getSecondRoll() {
		return secondRoll;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(71, 39).append(firstRoll).append(secondRoll)
				.toHashCode();
	}

	@Override
	public String toString() {
		return new StringBuilder("[").append(firstRoll).append(",")
				.append(secondRoll).append("]").toString();
	}
}